import store from '/@/stores/index';
// import Lxy_params_mgr from '/@/components/linxyun/custom/CustomCommon/lxy_params_mgr.js';
// import Lxy_expression from '/@/components/linxyun/custom/CustomCommon/lxy_expression.js';
// 处理数据
export const formatID = (id) => {
	if ([undefined, null, ''].includes(id)) return '---';
	const before = id.substring(0, 6);
	const after = id.substring(14);
	return before + '********' + after;
};

export const formatPhoneNumber = (phone) => {
	if ([undefined, null, ''].includes(phone)) return '---';
	const before = phone.substring(0, 3);
	const after = phone.substring(7);
	return before + '****' + after;
};

export const formatNumber = (number) => {
	if ([undefined, null, ''].includes(number)) return '---';
	return Number(number).toFixed(2);
};

export const getLocalStorage = (key) => {
	if ([undefined, null, ''].includes(key)) return '---';
	let storageKey;
	let isobj = false;
	if (key.indexOf('.') !== -1) {
		storageKey = key.substring(0, key.indexOf('.'));
		isobj = true;
	} else {
		storageKey = key;
	}
	let storageVal, storageObj;
	if (isobj) {
		storageObj = JSON.parse(localStorage.getItem(storageKey));
		let objVal = key.substring(key.indexOf('.') + 1).split('.');
		for (let i = 0; i < objVal.length; i++) {
			if (i === 0) {
				storageVal = storageObj[objVal[i]];
			} else {
				storageVal = storageVal[objVal[i]];
			}
		}
		return storageVal;
	} else {
		return localStorage.getItem(storageKey);
	}
};

export const getVuex = (key) => {
	if ([undefined, null, ''].includes(key)) return '---';
	let vuexObj = key.split('.');
	let model;
	console.log('getVuex vuexObj', vuexObj);
	for (let i = 0; i < vuexObj.length; i++) {
		if (i === 0) {
			console.log('store', store.state.value, vuexObj[i]);

			model = store.state.value[vuexObj[i]];
		} else {
			console.log('formatPrivacyData.js getVuex model: ', model);
			model = model[vuexObj[i]];
		}
	}
	console.log('getVuex model', model);
	return model;
};

export const getObjAttr = (obj, key) => {
	if ([undefined, null, ''].includes(key)) return '---';
	let keyArr = key.split('.');
	let model;
	for (let i = 0; i < keyArr.length; i++) {
		if (i === 0) {
			model = obj[keyArr[i]];
		} else {
			model = model[keyArr[i]];
		}
	}
	return model;
};

/**
 * 将不是数字的参数转成0
 */
export const nanTransformZero = (val) => {
	console.log('nanTransformZero val', val);
	try {
		if (isNaN(val) || val === '') return 0;
		return val;
	} catch (e) {
		return 0;
	}
};

/**
 * 取反
 * @param {*} val
 * @returns
 */
export const booleanNot = (val) => {
	console.log('booleanNot val', val, !val);
	return !val;
};

/**
 * 去除小数
 * @param {*} number
 * @returns
 */
export const formatRemoveDecimal = (number) => {
	if ([undefined, null, ''].includes(number)) return '---';
	return Number(number).toFixed(0);
};
/*
 * inputDataType ->  EInputDataType
 * inputDataName: 取值内容
 * inputDataType为0时在本方法不处理，由外部保障
 */

// export const calcFieldValue = (inputDataType, inputDataName, inputData, pageData, globalData) => {
// 	if (inputDataType && inputDataType >= 1 && inputDataType <= 4) {
// 		if (inputDataType == 2) {
// 			return inputDataName;
// 		} else if (inputDataType == 1) {
// 			if (inputDataName) {
// 				if (inputDataName.startsWith('Vuex.')) {
// 					const newInputDataName = inputDataName.slice('Vuex.'.length);
// 					console.log('calcFieldValue', inputDataName);
// 					return getVuex(newInputDataName);
// 				} else {
// 					return getObjAttr(inputData, inputDataName);
// 				}
// 			}
// 		} else if (inputDataType == 3) {
// 			const newInputDataName = inputDataName.slice('LocalStorage.'.length);
// 			return getLocalStorage(newInputDataName);
// 		} else {
// 			const datas = new Lxy_params_mgr(pageData, inputData, globalData);
// 			console.log('inputDataName', inputDataName, '', datas);
// 			const value = Lxy_expression.calPrefixExp(inputDataName, datas);
// 			if (value === undefined || value === null) {
// 				console.error('[Error][calcFieldValue]Call exp value for exp field, datas : ', datas, 'express: ', inputDataName);
// 				return null;
// 			} else {
// 				return value;
// 			}
// 		}
// 	} else {
// 		console.error('calcFieldValue, unsupport type: ', inputDataType);
// 		return null;
// 	}
// };
